package com.leyou.item.Service;

import com.leyou.item.mapper.CategoryMapper;
import com.leyou.item.pojo.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    //根据parentId查询子类目
    public List<Category> queryCategoryByPid(Long pid){
        Category category = new Category();
        category.setParentId(pid);
        return this.categoryMapper.select(category);
    }

    //向后台管理前端的商品查询提供接口
    //根据分类id查询名称
    public List<String> queryNamesByCid(List<Long> ids){

        List<Category> categories = this.categoryMapper.selectByIdList(ids);
        //调用方需要的是name，Category转name
        List<String> names = new ArrayList<>();
        for (Category category : categories) {
            names.add(category.getName());
        }
        return names;
    }
}
